const _config = require('config');
let showToast = (data) => {
  let defaultConf = {
    title: '成功',
    icon: 'success',
    duration: 1000,
    mask: true
  };
  let showToastConf = {
    ...defaultConf,
    ..._config.toastConfig,
    ...data
  };
  if (showToastConf.type == "error") {
    showToastConf.image = '/image/toast/showToast/error.png';
    delete showToastConf.type;
  }
  wx.showToast(showToastConf);
}

let showLoading = (data) => {
  let defaultConf = {
    title: '加载中...',
    mask: true,
  };
  let showLoadingConf = {
    ...defaultConf,
    ..._config.toastConfig,
    ...data
  };

  wx.showLoading(showLoadingConf);
}
let hideLoading = (data) => {
  wx.hideLoading(data);
}
let showModal = (data) => {

  let defaultConf = {
    title: '',
    content: '提示信息',
    showCancel: true,
  };
  let showModalConf = {
    ...defaultConf,
    ..._config.toastConfig,
    ...data
  };
  // if (showModal.type == "onlyOne") {
  //   defaultConf.showCancel=false;
  //   delete showToastConf.type;
  // }
  wx.showModal(showModalConf);
}

module.exports = {
  showToast: showToast,
  showLoading: showLoading,
  hideLoading: hideLoading,
  showModal: showModal
}